package com.omenkk.juc.c1;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.LockSupport;

@Slf4j
public class demo3 {
    public static void main(String[] args) throws InterruptedException {
        test3();
    }

    private static void test3()  throws  InterruptedException{
   Thread t1=new Thread(()->{
       log.debug("park...");
       log.debug("打断状态:{}",Thread.currentThread().isInterrupted());
       LockSupport.park();//阻塞线程
       //t1.interrupt();
log.debug("unpark");
log.debug("打断状态:{}",Thread.currentThread().isInterrupted());
//如果线程的中断状态已经是 true，调用 park() 不会阻塞，而是直接返回
     //  Thread.interrupted();//返回打断标记，并且如果为真，设置为假

       log.debug("打断状态:{}",Thread.interrupted());
       //已经被改为假
       log.debug("打断状态:{}",Thread.currentThread().isInterrupted());


       LockSupport.park();//阻塞线程
       //t1.interrupt();
       log.debug("unpark");

   });
   t1.start();
   Thread.sleep(1000);
   t1.interrupt();//interrupt() 设置中断标志

    }

}
